﻿using Hangfire;
using Hangfire.RecurringJobExtensions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace SX.Core.HangFire.Extension
{
    /// <summary>
    /// 扩展HangFire 便于微服务中多个服务引用组件
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 添加HangFire 使用redis缓存
        /// </summary>
        /// <param name="services"></param>
        /// <param name="redisConn">redis连接</param>
        /// <param name="jsonFile">job的json配置如："job1.json"</param>
        /// <returns></returns>
        public static IServiceCollection AddHangFire(this IServiceCollection services,string redisConn,string jsonFile)
        {
            services.AddHangfire(build =>
            {
                build.UseRedisStorage(redisConn);
                build.UseRecurringJob("recurringjob.json");
                build.UseDefaultActivator();
            });
            return services;
        }
    }
}
